package org.ucas.faker.web.Config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.ucas.faker.web.aop.DepotSwitcher;
import org.ucas.faker.web.aop.RequestLogger;

@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter{

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    RequestLogger logger = new RequestLogger();
    registry.addInterceptor(logger).addPathPatterns("/**")
        .excludePathPatterns("/**/*.css")
        .excludePathPatterns("/**/*.js")
        .excludePathPatterns("/**/*.png")
        .excludePathPatterns("/**/*.jpg")
        .excludePathPatterns("/**/*.gif")
        .excludePathPatterns("/**/*.jpeg")
        .excludePathPatterns("/**/*.html")
        .excludePathPatterns("/**/fonts/*");

    registry.addInterceptor(new DepotSwitcher()).addPathPatterns("/**");
  }
}
